/**
 * Created by XQ on 2015/7/21.
 */
$().ready(function(){

    $(".menu_item").each(function(index){
        $(this).bind("click", function(){
            $(".content.current").hide().removeClass("current");
            $(".content").eq(index).show().addClass("current");

            $(".menu_item.current").removeClass("current");
            $(this).addClass("current");
        });
    });

    $(".resume_item").each(function(index){
        $(this).bind("click", function(){

            $(".resume_content.current").hide().removeClass("current");
            $(".resume_content").eq(index).show().addClass("current");

            $(".resume_item.current").removeClass("current");
            $(this).addClass("current");
        });
    });

    $(".interview_item").each(function(index){
       $(this).bind("click", function(){

           $(".interview_content.current").hide().removeClass("current");
           $(".interview_content").eq(index).show().addClass("current");

           $(".interview_item.current").removeClass("current");
           $(this).addClass("current");
       }) ;
    });

    $("#addEdu").bind("click", function(){
        addEduRow();
    });

    $("#addExp").bind("click", function(){
        addExpRow();
    });

    $("#resumeForm").submit(function(){

        $(".eduRow").each(function(index){
            $(this).find(".school").attr("name", "eduList[" + index + "].school");
            $(this).find(".major").attr("name", "eduList[" + index + "].major");
            $(this).find(".degree").attr("name", "eduList[" + index + "].degree");
            $(this).find(".start_date").attr("name", "eduList[" + index + "].start_date");
            $(this).find(".end_date").attr("name", "eduList[" + index + "].end_date");
        });

        $(".expRow").each(function(index){
            $(this).find(".enterprise").attr("name", "expList[" + index + "].enterprise");
            $(this).find(".job").attr("name", "expList[" + index + "].job");
            $(this).find(".start_date").attr("name", "expList[" + index + "].start_date");
            $(this).find(".end_date").attr("name", "expList[" + index + "].end_date");
        });
    });
});

function prise(wbId){
    $.ajax({
        type: "POST",
        async: true,
        url: wp.config.baseUrl + "/rest/weibo/grant/prise?id="+wbId,
        dataType: "json",
        cache: false,
        random: Math.random(),
        success: function (json) {
            if (handleJsonResponse(json)) {
            }
        },
        error: function (json) {
            handleErrorJsonResponse(json);
        }
    });
}

function addEduRow(school, major, degree, startDate, endDate){

    var $div = $("<div>").addClass("eduRow"),
        len = $(".eduRow").length,
        $school = $("<input />").addClass("school").attr("name", "eduList[" + len + "].school").val(school || ""),
        $major = $("<input />").addClass("major").attr("name", "eduList[" + len + "].major").val(major || ""),
        $degree = $("<input />").addClass("degree").attr("name", "eduList[" + len + "].degree").val(degree || ""),
        $start_date = $("<input />").addClass("start_date").attr("name", "eduList[" + len + "].start_date").val(startDate || ""),
        $end_date = $("<input />").addClass("end_date").attr("name", "eduList[" + len + "].end_date").val(endDate || "");
    $div.append($("<div>").html("学校").append($school));
    $div.append($("<div>").html("专业").append($major));
    $div.append($("<div>").html("学位").append($degree));
    $div.append($("<div>").html("起始时间").append($start_date));
    $div.append($("<div>").html("结束时间").append($end_date));
    $(".resume_edu").append($div);
}

function addExpRow(enterprise, job, startDate, endDate){
    var $div = $("<div>").addClass("expRow"),
        len = $(".expRow").length,
        $school = $("<input />").addClass("enterprise").attr("name", "expList[" + len + "].enterprise").val(enterprise || ""),
        $major = $("<input />").addClass("job").attr("name", "expList[" + len + "].job").val(job || ""),
        $start_date = $("<input />").addClass("start_date").attr("name", "expList[" + len + "].start_date").val(startDate || ""),
        $end_date = $("<input />").addClass("end_date").attr("name", "expList[" + len + "].end_date").val(endDate || "");
    $div.append($("<div>").html("企业").append($school));
    $div.append($("<div>").html("职位").append($major));
    $div.append($("<div>").html("起始时间").append($start_date));
    $div.append($("<div>").html("结束时间").append($end_date));
    $(".resume_exp").append($div);
}